package com.etl.dataflow.executor.element;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

/**
 * @author dx
 * @since 2022/4/14
 */
public class DateColumn extends Column<Date> {

    public DateColumn(String name, Date date, int jdbcType, String jdbcTypeName) {
        super(name, date, jdbcType, jdbcTypeName);
    }

    @Override
    public String asString() {
        if (super.value == null) {
            return null;
        }
        Date date = new Date(super.getValue().getTime());
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }

    @Override
    public byte[] asBytes() {
        return new byte[0];
    }

    @Override
    public Timestamp asTimestamp() {
        return null;
    }

    @Override
    public Date asDate() {
        return super.value;
    }

    @Override
    public int getByteSize() {
        return value == null ? 0 : 24;
    }
}
